package com.zzxz.practicaltrainingsys.mapper;

import com.zzxz.practicaltrainingsys.entity.College;
import com.zzxz.practicaltrainingsys.entity.School;
import com.zzxz.practicaltrainingsys.entity.Topic;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface TopicMapper {
    @Select("select * from topic")
    public List<Topic> getTopic();

    //获取所有选题分类
    @Select("select DISTINCT topic_type from topic")
    public List<String> getTopicTypes();

    //根据项目id多表查取选题信息（选题名称、简介、应用技术）
    @Select("SELECT t.* FROM topic t " +
            "JOIN project p ON FIND_IN_SET(t.topic_id, p.topic_id) " +
            "WHERE p.project_id = #{project_id}")
    List<Topic> getTopicsByProjectId(@Param("project_id") Integer project_id);

    //增加选题
    @Insert("INSERT INTO topic (topic_name,topic_type,topic_introduction, topic_tec,topic_state) VALUES (#{topic_name}, #{topic_type}, #{topic_introduction},#{topic_tec},#{topic_state})")
    int insertTopic(Topic topic);

    //编辑选题
    @Update("update topic set topic_type=#{topic_type},topic_name=#{topic_name},topic_introduction=#{topic_introduction},topic_tec=#{topic_tec},topic_state=#{topic_state}\n"+
            "where Topic_id=#{topic_id}")
    int updateTopic(Topic topic);

    @Delete("delete from topic where topic_id=#{topic_id}")
     int  deleteTopicById(Integer topic_id);

    //根据选题分类查找选题名称
    @Select("select * from topic where topic_type = #{topic_type}")
    List<Topic> getTopicByTopicType(String topic_type);

    //查找选题状态
    @Select("select topic_state from topic where topic_id = #{topic_id}")
    String getTopicState(Integer topic_id);

    //在新增项目时更新选题状态
    @Update("update topic set topic_state = #{topic_state} where topic_id = #{topic_id}")
    int updateTopicStateWhenInsertProject(@Param("topic_id") Integer topic_id, @Param("topic_state") String topic_state);


    //根据学校编号查学校信息
    @Select("SELECT * FROM school WHERE school_id = #{school_id}")
    School getSchoolById(Integer school_id);
    //根据学院编号查询学院信息
    @Select("SELECT * FROM college WHERE college_id = #{college_id}")
    College getCollegeById(Integer college_id);
}
